package com.hsc.base;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * BaseServices接口
 * Created by admin on 2017/01/07.
 */
public interface FeatureTreeServices<T extends FeatureTree> {


    FeatureTreeRelation getFeatureTreeRelation();

    List<T> selectAll();


    /**
     * 获取后代节点。
     *
     * @param idList
     * @param includeSelf
     * @return
     */
    default List<T> selectDescendantsTree(Collection<String> idList, boolean includeSelf) {
        Set<String> idSet = getFeatureTreeRelation().getDescendants(idList, includeSelf);
        List<T> list = selectAll().stream().filter(item -> idSet.contains(item.getId())).collect(Collectors.toList());
        return list;
    }

    /**
     * 获取祖先节点。
     *
     * @param idList
     * @param includeSelf
     * @return
     */
    default List<T> selectAncestorsTree(Collection<String> idList, boolean includeSelf) {
        Set<String> idSet =getFeatureTreeRelation().getAncestors(idList, includeSelf);
        List<T> list = selectAll().stream().filter(item -> idSet.contains(item.getId())).collect(Collectors.toList());
        return list;
    }


}